﻿using Wisdom.Core;
using Wisdom.IoC.Unity;

namespace Wisdom.Core
{
    /// <summary>
    /// 描述：基于JiuZhou Fluent API路由，为Unity容器提供扩展方法
    /// </summary>
    public static class UnityContainerFluentExtender
    {
        #region IJiuZhouConfigurator Extensions
        /// <summary>
        /// 通过Unity对象容器配置JiuZhou框架
        /// </summary>
        /// <param name="configurator">这个 <see cref="IJiuZhouConfigurator"/>扩展实例.</param>
        /// <param name="containerInitFromConfigFile">值 <see cref="System.Boolean"/>标识配置容器是否能从配置文件中读取.</param>
        /// <param name="containerConfigSectionName">配置文件结点名称，当 <paramref name="containerInitFromConfigFile"/>值设为True，则该名称必须配置.</param>
        /// <returns> <see cref="IObjectContainerConfigurator"/> 实例.</returns>
        public static IObjectContainerConfigurator UsingUnityContainerWithDefaultSettings(this IJiuZhouConfigurator configurator, bool containerInitFromConfigFile = false, string containerConfigSectionName = null)
        {
            return configurator.WithDefaultSettings().UsingUnityContainer(containerInitFromConfigFile, containerConfigSectionName);
        }
        #endregion

        #region ISequenceGeneratorConfigurator Extensions
        /// <summary>
        /// 通过使用Unity对象容器配置JiuZhou框架
        /// </summary>
        /// <param name="configurator">被扩展 <see cref="ISequenceGeneratorConfigurator"/> 类型实例.</param>
        /// <param name="initFromConfigFile">值 <see cref="System.Boolean"/>标识配置容器是否能从配置文件中读取 .</param>
        /// <param name="sectionName">配置文件结点名称. 当 <paramref name="initFromConfigFile"/> 设置为 true时，其名称为必须填.</param>
        /// <returns>类 <see cref="IObjectContainerConfigurator"/> 实例.</returns>
        public static IObjectContainerConfigurator UsingUnityContainer(this ISequenceGeneratorConfigurator configurator, bool initFromConfigFile = false, string sectionName = null)
        {
            return configurator.UsingObjectContainer<UnityObjectContainer>(initFromConfigFile, sectionName);
        }
        #endregion

        #region IExceptionHandlerConfigurator Extensions
        /// <summary>
        /// 通过使用Unity对象容器配置JiuZhou框架.
        /// </summary>
        /// <param name="configurator">被扩展 <see cref="IExceptionHandlerConfigurator"/> 类型实例.</param>
        /// <param name="initFromConfigFile">值 <see cref="System.Boolean"/>标识配置容器是否能从配置文件中读取.</param>
        /// <param name="sectionName">配置文件结点名称. 当 <paramref name="initFromConfigFile"/> 设置为 true时，其名称为必须填.</param>
        /// <returns>类 <see cref="IObjectContainerConfigurator"/> 实例.</returns>
        public static IObjectContainerConfigurator UsingUnityContainer(this IExceptionHandlerConfigurator configurator, bool initFromConfigFile = false, string sectionName = null)
        {
            return configurator.UsingObjectContainer<UnityObjectContainer>(initFromConfigFile, sectionName);
        }
        #endregion

        #region IInterceptionConfigurator Extensions
        /// <summary>
        /// 通过使用Unity对象容器配置JiuZhou框架.
        /// </summary>
        /// <param name="configurator">被扩展 <see cref="IInterceptionConfigurator"/> 类型实例.</param>
        /// <param name="initFromConfigFile">值 <see cref="System.Boolean"/>标识配置容器是否能从配置文件中读取.</param>
        /// <param name="sectionName">配置文件结点名称. 当 <paramref name="initFromConfigFile"/> 设置为 true时，其名称为必须填.</param>
        /// <returns>类 <see cref="IObjectContainerConfigurator"/> 实例.</returns>
        public static IObjectContainerConfigurator UsingUnityContainer(this IInterceptionConfigurator configurator, bool initFromConfigFile = false, string sectionName = null)
        {
            return configurator.UsingObjectContainer<UnityObjectContainer>(initFromConfigFile, sectionName);
        }
        #endregion
    }
}
